package com.dudy.authdemo.service.impl;

import com.dudy.authdemo.mapper.MenuMapper;
import com.dudy.authdemo.model.Menu;
import com.dudy.authdemo.service.MenuService;
import com.dudy.authdemo.vo.MenuVO;
import com.dudy.common.base.PageData;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

/**
 * @program: auth
 * @author: dudy
 * @create: 2020-12-15 17:34
 * @description:
 **/
@Service
public class MenuServiceImpl extends BaseServiceImpl<Menu, MenuVO> implements MenuService {

    @Resource
    private MenuMapper menuMapper;

    @Override
    public List<MenuVO> queryCurrentMenu(@NotBlank String userName) {
        List<Menu> menus = menuMapper.queryCurrentMenu(userName);
        if (CollectionUtils.isEmpty(menus)) {
            return new ArrayList<>();
        }
        List<MenuVO> menuVOS = new ArrayList<>(menus.size());
        menus.forEach(menu -> {
            MenuVO menuVO = new MenuVO();
            BeanUtils.copyProperties(menu, menuVO);
            menuVOS.add(menuVO);
        });
        return menuVOS;
    }

    @Override
    public MenuVO create() {
        return new MenuVO();
    }

}
